package com.xiong.xtools.switchbutton;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.xiong.xtools.R;

/**
 * Author : 熊文强
 * Time : 2017/9/19
 * Content : 选择开关按钮
 * switch_button_attrs.xml、SwitchButton.java
 */
public class SwitchButtonActivity extends AppCompatActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_switch_button);

		SwitchButton switchButton = (SwitchButton) findViewById(R.id.switch_button);

		switchButton.setChecked(true);
		switchButton.isChecked();
		switchButton.toggle();     //switch state
		switchButton.toggle(false);//switch without animation
		switchButton.setShadowEffect(true);//disable shadow effect
		switchButton.setEnabled(true);//disable button
		switchButton.setEnableEffect(false);//disable the switch animation
		switchButton.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(SwitchButton view, boolean isChecked) {
				if (isChecked){
					Toast.makeText(SwitchButtonActivity.this,"开",Toast.LENGTH_SHORT).show();
				}else {
					Toast.makeText(SwitchButtonActivity.this,"关",Toast.LENGTH_SHORT).show();
				}
			}
		});

	}
}
